package cn.kane.command;

public class Calendar implements ICalendar {

	private int result = 0 ;
	
	@Override
	public void calc(char operator, int value) {
		int newValue = 0 ;
		switch(operator){
		case '+' : newValue = result + value ; break ;
		case '-' : newValue = result - value ; break ;
		case '*' : newValue = result * value ; break ;
		case '/' : newValue = result / value ; break ;
		}
		System.out.println("CALC:"+result+operator+value+"="+newValue);
		this.setResult(newValue);
	}

	@Override
	public void undo(char operator, int value) {
		int newValue = 0 ;
		switch(operator){
		case '+' : operator='-'; newValue = result - value ; break ;
		case '-' : operator='+'; newValue = result + value ; break ;
		case '*' : operator='/'; newValue = result / value ; break ;
		case '/' : operator='*';newValue = result * value ; break ;
		}
		System.out.println("UNDO:"+result+operator+value+"="+newValue);
		this.setResult(newValue);
	}

	public int getResult() {
		return result;
	}

	private void setResult(int result) {
		this.result = result;
	}

}
